#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include <QTimer>


MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //点击退出菜单选项，实现退出
    connect(ui->actionQuit,&QAction::triggered,[=](){
        this->close();
    });

    //设置固定尺寸
    this->setGeometry(QRect(400,150,320,588));
    //设置标题
    this->setWindowTitle("翻金币");
    //设置图标
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));

    //创建第二个选关场景
    this->chooseScene=new ChooseLevelScene;

    //创建开始按钮
    MyPushButton *startBtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
    connect(startBtn,&MyPushButton::clicked,[=](){
        qDebug()<<"进入选关场景";
        //向上跳跃
        startBtn->zoom1();
        //向下跳跃
        startBtn->zoom2();

        //延时进入第二个场景
        QTimer::singleShot(400,this,[=](){
            this->chooseScene->show();
            this->hide();
        });

    });
    //监听返回按钮信号
    connect(this->chooseScene,&ChooseLevelScene::ChooseSceneBack,[=](){
        this->show();
        this->chooseScene->hide();
    });

}


//绘图事件
void MainScene::paintEvent(QPaintEvent *)
{
    //创建画家对象
    QPainter painter(this);
    //创建QPixmap对象
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    //绘制背景
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //加载标题
     pix.load(":/res/Title.png");
     //缩放图片
     pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
     //绘制图片
     painter.drawPixmap(10,30,pix);

}



MainScene::~MainScene()
{
    delete ui;
}

